<div class="layuimini-main">

    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名：</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名"
                       value="" class="layui-input">
                <tip>填写用户管理和登录的账号。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">用户密码：</label>
            <div class="layui-input-block">
                <input type="password" name="password" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码"
                       value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">真实姓名：</label>
            <div class="layui-input-block">
                <input type="text" name="realName" lay-verify="required" lay-reqtext="真实姓名不能为空"
                       placeholder="请输入真实姓名"
                       value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">用户类别：</label>
            <div class="layui-input-block">
                <select name="userTypeId" lay-verify="required">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">医生职称：</label>
            <div class="layui-input-block">
                <select name="docTitleId" lay-verify="required">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">是否排班：</label>
            <div class="layui-input-block">
                <input type="radio" name="isScheduling" value="是" title="是" checked="">
                <input type="radio" name="isScheduling" value="否" title="否">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">所在科室：</label>
            <div class="layui-input-block">
                <select name="deptId" lay-verify="required">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">挂号级别：</label>
            <div class="layui-input-block">
                <select name="registLeId" lay-verify="required">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        $.getJSON("/api/select/userType.json", function (data) {
            data.forEach(e => {
                $("select[name=userTypeId]").append("<option value='" + e.id + "'>" + e.name + "</option>");
            });
            form.render();
        });
        $.getJSON("/api/select/constItem.json", {constantTypeId: 8}, function (data) {
            data.forEach(e => {
                $("select[name=docTitleId]").append("<option value='" + e.id + "'>" + e.name + "</option>");
            });
            form.render();
        });
        $.getJSON("/api/select/deptName.json", function (data) {
            data.forEach(e => {
                $("select[name=deptId]").append("<option value='" + e.id + "'>" + e.name + "</option>");
            });
            form.render();
        });
        $.getJSON("/api/select/registLe.json", function (data) {
            data.forEach(e => {
                $("select[name=registLeId]").append("<option value='" + e.id + "'>" + e.name + "</option>");
            });
            form.render();
        });
        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index1 = layer.load(2);
            $.get("/api/user/add.json", data.field, function (data) {
                layer.close(index1);
                if (data.code == 0) {
                    var index = layer.alert(data.msg, {
                        title: '错误信息',
                        icon: 2
                    });
                } else {
                    layer.close(parentIndex);
                }
            }, "json");
            return false;
        });

    });
</script>